import request from '@/utils/request'
// import qs from 'qs'

// 管理员管理

// 修改多鉴别状态（Ukey）
export function editUkey (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/editUkey',
    method: 'post',
    data
  })
}

// 修改管理员密码
export function editPassword (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/editPassword',
    method: 'post',
    data
  })
}

// 修改管理员角色
export function editRole (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/editRole',
    method: 'post',
    data
  })
}

// 修改管理员锁定状态
export function editBanned (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/editBanned',
    method: 'post',
    data
  })
}

// 删除管理员
export function delAdministrators (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/del_administrators',
    method: 'post',
    data
  })
}

// 删除管理员
export function addAdmin (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/addAdmin',
    method: 'post',
    data
  })
}

// 显示所有管理员
export function getAdminArray (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/getAdminArray',
    method: 'post',
    data
  })
}

// 绑定Ukey
export function bindUkey (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/bindUkey',
    method: 'post',
    data
  })
}

// 获取随机密钥对
export function getRandomKey (params) {
  var data = fromData(params)
  return request({
    url: '/administrators/getRandomKey',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
